import React from 'react'
import { Redirect } from 'react-router-dom'
import { IRouterSet, withAuthorize, withParameters } from '../widgets/RouterView'
import Editorial from '../pages/Editorial'
import Following from '../pages/Follwing'
import Topic from '../pages/Topic'
import UserProfile from '../pages/UserProfile'
import UserProfilePhotos from '../pages/UserProfile/UserProfilePhotos'
import UserProfileLike from '../pages/UserProfile/UserProfileLike'
import UserProfileCollections from '../pages/UserProfile/UserProfileCollections'
import AccountSetting from '../pages/AccountSetting'
import Profile from '../pages/AccountSetting/Profile'
import ChangePassword from '../pages/AccountSetting/ChangePassword'
import CloseAccount from '../pages/AccountSetting/CloseAccount'
import Search from '../pages/Search'
import SearchPhotos from '../pages/Search/SearchPhotos'
import SearchCollections from '../pages/Search/SearchCollections'
import SearchUser from '../pages/Search/SearchUser'
import User from '../pages/User'
import Collection from '../pages/Collection'
import UserPhotos from '../pages/User/UserPhotos'
import UserLike from '../pages/User/UserLike'
import UserCollections from '../pages/User/UserCollections'
import Account from '../pages/Account'
import Photos from '../pages/Photos'
import License from '../pages/LineViewLicense/License'
import PrivacyPolicy from '../pages/LineViewLicense/PrivacyPolicy'
import TermsConditions from '../pages/LineViewLicense/TermsConditions'

const routers: IRouterSet = {
    editorial: {
        name: 'Editorial',
        component: Editorial
    },
    following: {
        name: 'Following',
        component: withParameters('/following/{userId}', Following)
    },
    photos: {
        name: 'Photos',
        component: withParameters('/photos/{imgId}', Photos)
    },
    topic: {
        name: 'Topic',
        component: withParameters('/topic/{type}', Topic)
    },
    // collection: {
    //     name: 'Collection',
    //     component: withParameters('/collection/{collectionId}', Collection)
    // },
    account: {
        name: 'Account',
        component: withParameters('/account/{accountType}', Account)
    },
    user: {
        name: 'User',
        component: withParameters('/user/{type}/{userId}', User),
        children: {
            photos: {
                name: 'Photos',
                component: withParameters('/photos/{userId}', UserPhotos)
            },
            like: {
                name: 'Like',
                component: withParameters('/like/{userId}', UserLike)
            }
            // collections: {
            //     name: 'Collections',
            //     component: withParameters('/collections/{userId}', UserCollections)
            // }
        }
    },
    profile: {
        name: 'profile',
        component: withParameters('/profile/{type}/{userId}', UserProfile),
        children: {
            photos: {
                name: 'Photos',
                component: withParameters('/profile/photos/{userId}', UserProfilePhotos)
            },
            like: {
                name: 'Like',
                component: withParameters('/profile/like/{userId}', UserProfileLike)
            }
            // collections: {
            //     name: 'Collections',
            //     component: withParameters('/profile/collections/{userId}', UserProfileCollections)
            // }
        }
    },
    search: {
        name: 'Search',
        component: withParameters('/search/{type}/{searchValue}', Search),
        children: {
            photos: {
                name: 'Photos',
                component: withParameters('/photos/{searchValue}', SearchPhotos)
            },
            // collections: {
            //     name: 'Collections',
            //     component: withParameters('/collections/{searchValue}', SearchCollections)
            // },
            user: {
                name: 'User',
                component: withParameters('/user/{searchValue}', SearchUser)
            }
        }
    },
    account_setting: {
        name: 'accountSetting',
        component: withParameters('/account_setting/{type}/{userId}', AccountSetting),
        children: {
            profile: {
                name: 'Profile',
                component: withParameters('/profile/{userId}', Profile)
            },
            change_password: {
                name: 'ChangePassword',
                component: withParameters('/change_password/{userId}', ChangePassword)
            },
            close_account: {
                name: 'CloseAccount',
                component: withParameters('/close_account/{userId}', CloseAccount)
            }
        }
    },
    license: {
        name: 'License',
        component: License
    },
    policy: {
        name: 'PrivacyPolicy',
        component: PrivacyPolicy
    },
    terms: {
        name: 'TermsConditions',
        component: TermsConditions
    }
}

function CheckAuth(component: any) {
    return withAuthorize(
        () => localStorage.getItem('token') as any,
        // 你也可以直接重定向到某个页面
        // <Redirect to="/home/welcome"></Redirect>
        <Redirect to="/home" />
    )(component)
}

export default routers
